package com.wnxy.pms.order.core.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.wnxy.pms.order.core.entity.OrderItem;
import com.wnxy.pms.order.core.mapper.OrderItemMapper;
import com.wnxy.pms.order.core.service.IOrderItemService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wnxy.pms.order.core.vo.OrderItemVo;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 订单中所包含的商品 服务实现类
 * </p>
 *
 * @author Jet
 * @since 2022-06-09
 */
@Service
public class OrderItemServiceImpl extends ServiceImpl<OrderItemMapper, OrderItem> implements IOrderItemService {

    @Override
    public List<OrderItemVo> findByOrderSn(String orderSn) {
        LambdaQueryWrapper<OrderItem> wrapper = Wrappers.lambdaQuery();
        wrapper.select(OrderItem::getProductName,OrderItem::getProductPrice,
                OrderItem::getProductQuantity);
        wrapper.eq(OrderItem::getOrderSn,orderSn);
        List<Map<String,Object>> list = baseMapper.selectMaps(wrapper);
        return BeanUtil.copyToList(list,OrderItemVo.class);
    }
}
